package com.gxa.controller;

import com.gxa.common.JsonResult;
import com.gxa.common.R;
import com.gxa.pojo.AS_Contact_Customer;
import com.gxa.pojo.After_Sales;
import com.gxa.pojo.Customer;
import com.gxa.service.AfterSalesService;
import com.gxa.utils.FileListUtils;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;


/**
 * 售后信息接口类
 */
@Controller
@RequestMapping(value = "/afterSales")
@Api(value = "售后模板test",tags = "售后模板接口API")
public class AfterSalesController {
    @Autowired
    private AfterSalesService afterSalesService;
    @RequestMapping(value = "/queryList" ,method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "售后列表默认查询，状态分类查询，高级查询接口",notes = "售后列表默认查询，状态分类查询，高级查询接口",httpMethod = "post", response = JsonResult.class)
    @ApiResponses({
            @ApiResponse(code=200,message="请求成功"),
            @ApiResponse(code=300,message="数据类型错误"),
            @ApiResponse(code=500,message="后台服务错误")
    })
    //售后列表默认查询，状态分类查询，高级查询接口
    public JsonResult queryList(@RequestBody Map<String,String> map){
        return afterSalesService.queryList(map);
    }
    @RequestMapping(value = "/specificQueryList" ,method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "指定查询接口",notes = "指定查询接口",httpMethod = "post", response = JsonResult.class)
    //售后列表指定查询接口specific
    public JsonResult specificQueryList(@RequestBody Map<String,String> map){
        return afterSalesService.specificQueryList(map);
    }
    @RequestMapping(value = "/upDate",method = RequestMethod.POST)
    @ApiOperation(value = "售后信息修改接口",notes = "上传formdata数据",httpMethod = "post", response = R.class)
    @ResponseBody
    public R upDate(@RequestBody AS_Contact_Customer after_sales) throws IOException {
        return afterSalesService.upDate(after_sales);
    }
    @RequestMapping(value = "/del",method = RequestMethod.POST)
    @ApiOperation(value = "售后信息删除接口",notes = "上传a_s_id 售后信息ID",httpMethod = "post", response = R.class)
    @ResponseBody
    public R del(@RequestBody After_Sales after_sales){
        return afterSalesService.del(after_sales.getA_s_id());
    }

    @RequestMapping(value = "/addForm",method = RequestMethod.POST)
    @ApiOperation(value = "售后信息新增接口",notes = "新增售后信息",httpMethod = "post", response = R.class)
    @ResponseBody
    public R addForm(@RequestBody  After_Sales after_sales) throws IOException {
        return afterSalesService.addForm(after_sales);
    }
    @RequestMapping(value = "/queryEmp",method = RequestMethod.POST)
    @ApiOperation(value = "员工查询接口",notes = "查询所有员工",httpMethod = "post", response = R.class)
    @ResponseBody
    public R queryEmp(){
        return afterSalesService.queryEmp();
    }
    @RequestMapping(value = "/queryGoods",method = RequestMethod.POST)
    @ApiOperation(value = "商品查询",notes = "根据客户ID 查询当前商品",httpMethod = "post", response = R.class)
    @ResponseBody
    public R queryGoods(@RequestBody  After_Sales after_sales){
        return afterSalesService.queryGoods(after_sales.getCustomer_id());
    }
    @RequestMapping(value = "/countUnderEmp",method = RequestMethod.GET)
    @ApiOperation(value = "售后统计",notes = "售后按照员工统计",httpMethod = "GET", response = R.class)
    @ResponseBody
    public R countUnderEmp(){
        return afterSalesService.countUnderEmp();
    }
    @RequestMapping(value = "/countUnderDept",method = RequestMethod.GET)
    @ApiOperation(value = "售后统计",notes = "售后按照部门统计",httpMethod = "GET", response = R.class)
    @ResponseBody
    public R countUnderDept(){
        return afterSalesService.countUnderDept();
    }
    @RequestMapping(value = "/delCustomerOrders",method = RequestMethod.POST)
    @ApiOperation(value = "删除售后订单",notes = "根据客户ID 删除对应售后订单",httpMethod = "POST", response = R.class)
    @ResponseBody
    public R delCustomerOrders(@RequestBody Customer customer){
        return afterSalesService.delCustomerOrders(customer.getCustomer_id());
    }


    @RequestMapping(value = "/updateFile",method = RequestMethod.POST)
    @ApiOperation(value = "多文件上传接口",notes = "多文件上传接口",httpMethod = "POST", response = R.class)
    @ResponseBody
    public R test(List<MultipartFile> file, HttpServletRequest request) throws IOException {
        System.out.println(file);
        String url = FileListUtils.upData(file,request);
        R r = new R ();
        r.setData(url);
        return r;
    }
}
